﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON

GO

CREATE TABLE dbo.bht_Version
(
	Feature nvarchar(400) NOT NULL,
	DbVersion int NOT NULL
)  ON [PRIMARY]
GO


CREATE PROCEDURE bhp_GetVersion
(
	@Feature			NVARCHAR(400)
)
AS
	IF EXISTS (SELECT 1 FROM bht_Version WHERE Feature = @Feature)
		SELECT DbVersion FROM bht_Version WHERE Feature = @Feature
	ELSE
		SELECT 0 AS DbVersion

GO

CREATE PROCEDURE bhp_SetVersion
(
	@Feature			NVARCHAR(400),
	@Version			INT
)
AS
	IF EXISTS (SELECT 1 FROM bht_Version WHERE Feature = @Feature)
		UPDATE
			bht_Version 
		SET
			DbVersion		= @Version
		WHERE 
			Feature			= @Feature
	ELSE
		INSERT INTO bht_Version		(Feature,		DbVersion)
						VALUES							(@Feature, @Version)

GO
